package sk.sigp.aobot.swinggui;

import java.awt.Component;
import java.awt.Font;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;

import sk.sigp.aobot.Colors;
import sk.sigp.aobot.base.Buddy;

class BuddyRenderer extends DefaultListCellRenderer {

	private static final long serialVersionUID = 1L;

	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		JLabel l = new JLabel();
		if (value instanceof Buddy) {
			Buddy buddy = (Buddy) value;
			l.setText(buddy.name);
			if (isSelected) {
				l.setOpaque(true);
				l.setBackground(Colors.SELECTED);
			}
			Font f = new Font(l.getFont().getName(), 0, l.getFont()
					.getSize());
			l.setFont(f);
			if (buddy.online == 1)
				l.setForeground(Colors.ONLINE_BUDDY);
			else
				l.setForeground(Colors.OFFLINE_BUDDY);
		}
		return l;
	}

}